export const Tag = {
	state: {
		tagList: [],
	},
	mutations: {
        /**
         * 
         * @param {*} state 
         * @param {*} tag = {path:'/user/list',title:'会员列表'}
         */
		SAVE_TAGLIST(state, tag) {
			// 去掉重复的标签
			let isOk =  state.tagList.some(item=>item.path==tag.path)
			if(isOk) return
			state.tagList.push(tag)
		},
		
		CLEAR_TAG(state) {
			state.tagList = [] 
		},
		
		//关闭标签
		CLOSE_TAG(state,tag){
			let index = state.tagList.findIndex(item=>item.path == tag.path)
			state.tagList.splice(index,1)
		}
	},
	actions: {
		saveTag({ commit }, tag) {
			commit('SAVE_TAGLIST', tag)
		},
		
		clearTag({ commit }) {
			commit('CLEAR_TAG')
		},

		closeTag({commit},tag){
			commit('CLOSE_TAG',tag)
		}
	}
}